-
-
Notifications
You must be signed in to change notification settings - Fork 215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid notify listener calls on field register when there's no subscriber #319
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talk to me about the performance problem. How much of an effect does this change have on the performance? How many fields do you have?
@erikras The problem is prominent when you use For example, we had more than 600 fields subscribed in one screen, when the field initializes, it registers, notifies all subscribers, then removes itself for the initial state (I think act of removing also notifies the subscribers again, if I recall?), then re-registers to setup the |
I'm trying to make a (A lot of my code I'm migrating from Right now it seems like the only way to make this hook is to use a custom mutator to poke the subscription and listener into |
@erikras I tried my approach outlined above but there's no way to subscribe to the value of an individual field if no |
Hello, I'm trying to address an issue with performance in react-final-form: final-form/react-final-form#667
The only way I could do this was to separate the registration and subscription of the field, slightly modifying the current
registerField
api to optionally accept the subscriber.The major performance issue that I've found with react-final-form was that it was using
registerField
to register for the first time to get the initial values, unregister, then register again for subscribing to the subsequent updates to the form. And each time it registered, it fired off notify subscription on all previously registered fields. So, if you are trying to render 100 fields on the screen, that's 2 registration per field and 10100 orn(n + 1)
notifications, I think. :)Anyway, I was trying to optimize this by not having to call notification on registration and avoid the second registration, so I've updated the api to what you see here.
I'll PR my changes for react-final-form shortly.React-final-form changes: final-form/react-final-form#727